#include<stdio.h>
#include"binary.h"

#define var_num 30//变元数
#define equ_num 19//方程数

int main()
{
	FileContent Orgin = openfile("C:\\Users\\WJG\\source\\repos\\Project1\\1.txt","rb");
	FileContent Result = openfile("C:\\Users\\WJG\\source\\repos\\Project1\\2.txt", "wb");

	uint8_t* ch = (uint8_t *)malloc(sizeof(uint8_t) * Orgin.file_length);
	uint8_t* bch = (uint8_t *)malloc(sizeof(uint8_t) * Orgin.file_length*8);
    if (ch == NULL) { printf("Empty file."); return 0; }

	fread(ch, 1, Orgin.file_length, Orgin.filename);

	byte2bit(bch, ch, ceil((equ_num * var_num) / 8.0));
    memset(bch + equ_num * var_num, 0, 8*ceil((equ_num * var_num) / 8.0)- equ_num * var_num);
	
    //printMatrix(bch,equ_num, var_num);

    gaussian_elimination( bch, equ_num, var_num);

    //printMatrix(bch, equ_num, var_num);
    
    bit2byte(ch, bch, ceil((equ_num * var_num) / 8.0));
    fwrite(ch,1, ceil((equ_num * var_num) / 8.0),Result.filename);
    
    fclose(Orgin.filename);
    fclose(Result.filename);
	system("pause");
	return 0;
}